﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;


public partial class Controls_Products_ctrPackage : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindProduct();
        }
    }

    private void BindProduct()
    {
        int nCurentLanguage = Support.GetCurrentLanguage();
        switch (nCurentLanguage )
        {
            case 1:
                lblPackage.Text = "Gói tư vấn trực tuyến"; 
                break;
            case 2:
                lblPackage.Text = "Online Consutancy Package "; 
                break;
            case 3:
                lblPackage.Text = "Online Consutancy Package "; 
                break;
        }
        int nPagecount = 0;
        Products objProduct = new Products();
        DataTable dtbProduct = new DataTable();
        dtbProduct = objProduct.Search(0, "", "", 0, "", 0, 0, 0, 100000000, -1,-1, 1, 0, 0, 0, nDefaultLanguage, nCurrentLang, 1, 5, ref nPagecount);
        rptPackage.DataSource = dtbProduct;
        rptPackage.DataBind();
    }

    protected void rptPackage_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nCurentLanguage = Support.GetCurrentLanguage();

        string sPrice = string.Empty;
        string sContact = string.Empty;

        sPrice = MultipleLanguage.PRICE[nCurrentLang - 1] + ": ";
        sContact = MultipleLanguage.PRICE_CALL[nCurrentLang - 1];

        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkName = (HyperLink)e.Item.FindControl("lnkName");
            Label lblPrice = (Label)e.Item.FindControl("lblPrice");
            HyperLink lnkFeatures = (HyperLink)e.Item.FindControl("lnkFeatures");
            Image imgImage = (Image)e.Item.FindControl("imgImage");
            Label lbName = (Label)e.Item.FindControl("lbName");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "ProductID"));

            string strImages = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ImageDefault"));
            if (strImages.Length > 0) { imgImage.ImageUrl = Config.ROOT + Config.IMAGE_PRODUCT_DEFAULT_UPLOAD + strImages; }
            else { imgImage.ImageUrl = Config.ROOT + Config.IMAGE_NO_IMAGE; }
            lnkName.NavigateUrl = Config.ROOT + Pages.FrontEnds.PRODUCT_DETAIL + "?" + Config.PRO_ID + "=" + nID;
            lbName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductName"));

            double dPrice = ConvertData.ConvertToDouble(DataBinder.Eval(e.Item.DataItem, "Price"));
            if (dPrice > 0)
            { lblPrice.Text = sPrice + ConvertData.ConvertToString(Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "Price"))) + " " + "₫"; }
            else { lblPrice.Text = sPrice + sContact; }




            string sContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "MainContent"));
            if (sContent.Length > 173)
            {
                sContent = ConvertData.TruncateString(sContent, 173) + Config.DOT;
            }


            lnkFeatures.Text = sContent;

        }
    }
    protected void rptPackage_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}
